package myta.service;

import java.sql.PreparedStatement;
import java.sql.ResultSet;

import myta.model.DataTable;

public class Command {
	private PreparedStatement ps;
	
	public void setQuery(String sql) throws Exception{
		ps = Database.dbConnection.prepareStatement(sql);
	}
	
	public void setObject(int index, Object obj) throws Exception{
		ps.setObject(index, obj);
	}
	
	public DataTable executeQuery() throws Exception{
		ResultSet rs = ps.executeQuery();
		DataTable dt = new DataTable();
		dt.setDatatable(rs);
		return dt;
	}
	
	public boolean executeUpdate() throws Exception{
		int i = ps.executeUpdate();
		
		if(i>0){
			return true;
		}
		
		return false;
	}
}
